#!/bin/bash

root_directory="/path/to/root/directory"
log_file="/path/to/log/file.log"

# 定义需要排除的文件名和目录名列表
excluded_files=(
  "/path/to/excluded/file1.txt"
  "/path/to/excluded/file2.jpg"
)
excluded_directories=(
  "/path/to/excluded/directory1"
  "/path/to/excluded/directory2"
)

# 删除超过15天的文件（排除指定文件和目录），并记录到日志
find "$root_directory" -type f -mtime +15 ! -path "${excluded_files[@]}" -print -delete -exec echo "Deleted file: {}" >> "$log_file" \;

# 删除空目录（排除指定目录），并记录到日志
find "$root_directory" -type d -empty ! -path "${excluded_directories[@]}" -print -delete -exec echo "Deleted directory: {}" >> "$log_file" \;
